package com.ylr.Scheduled;

import com.ylr.bean.Mymap;
import lombok.extern.log4j.Log4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @ClassName ScheduleTask
 * @Description TODO
 * @Author 11
 * @Date 2021/7/6 10:37
 * @Version 1.0
 */


//@Component
public class ScheduleTask {
    public  static Logger log= LoggerFactory.getLogger(ScheduleTask.class);
    public volatile AtomicInteger count = new AtomicInteger(0);
//    public volatile ConcurrentHashMap<String,String> hashMap = new Mymap().getMap();



    @Scheduled(cron = "${ScheduleTask.Check.cron}")
    @Async
    public void Check() throws InterruptedException {
        String tmp=count.toString();
        count.incrementAndGet();
        log.info("Check 开始 {} 任务 {}",tmp,new Date());
//        hashMap.put(tmp,"Check 开始  "+tmp+" 任务 "+new Date());
        Thread.sleep(10000);
//        count.incrementAndGet();
        log.info("Check 结束 {} 任务 {}",tmp,new Date());
//        hashMap.put(tmp,hashMap.get(tmp).toString()+"\n" + "Check 结束  "+tmp+" 任务 "+new Date());
    }

    @Scheduled(cron = "${ScheduleTask.Check1.cron}")
    @Async
    public void Check1() throws InterruptedException {
        String tmp=count.toString();
        count.incrementAndGet();
//        hashMap.put(tmp,"Check1 开始  "+tmp+" 任务 "+new Date());
        log.info("Check1 开始 {} 任务 {}",tmp,new Date());

        Thread.sleep(10000);
//        while (true){
//
//        }

//        hashMap.put(tmp,hashMap.get(tmp).toString() + "Check1 结束  "+tmp+" 任务 "+new Date()+"  |    ");
        log.info("Check1 结束 {} 任务 {}",tmp,new Date());
    }

}
